package com.situ.day5;

import org.junit.Test;

import java.util.Arrays;
import java.util.Scanner;

public class ArrayDemo {

    @Test
    public void test1() {
        int[][] array = new int[2][3];
        array[0][0] = 1;
        array[0][1] = 2;
        array[0][2] = 3;
        array[1][0] = 4;
        array[1][1] = 5;
        array[1][2] = 6;
        System.out.println(array.length);
        for (int i = 0; i < array.length; i++) {
            //[1, 2, 3]
            //System.out.println(Arrays.toString(array[i]));
            for (int j = 0; j < array[i].length; j++) {
                System.out.print(array[i][j] + " ");
            }
            System.out.println();
        }

    }

//    1、int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
//    求出上面数组中0-9分别出现的次数
//    双重for循环
    @Test
    public void test2() {
        int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
        int count0 = 0;
        int count1 = 0;
        int count2 = 0;
        for (int i = 0; i < scores.length; i++) {
            switch (scores[i]) {
                case 0:
                    count0++;
                    break;
                case 1:
                    count1++;
                    break;
                case 2:
                    count2++;
                    break;
            }
        }

        System.out.println("0出现的次数：" + count0);
        System.out.println("1出现的次数：" + count1);
        System.out.println("2出现的次数：" + count2);

    }

    @Test
    public void test3() {
        int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
        int[] counts = new int[10];
        //counts[0]  counts[0]++
        //counts[1]  counts[1]++
        //counts[2]  counts[2]++
        //counts[3]  counts[3]++
        //int count0 = 0;   count0++
        //int count1 = 0;
        //int count2 = 0;
        // count3 = 0;
        for (int i = 0; i < scores.length; i++) {
            switch (scores[i]) {
                case 0:
                    counts[0]++;
                    break;
                case 1:
                    counts[1]++;
                    break;
                case 2:
                    counts[2]++;
                    break;
            }
        }

        for (int i = 0; i < counts.length; i++) {
            System.out.println(i + "出现的次数：" + counts[i]);
        }
    }

//    2、int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
//    要求求出其中的奇数个数和偶数个数。
    @Test
    public void test4() {
        int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
        int oddCount = 0;
        int evenCount = 0;
        for (int i = 0; i < scores.length; i++) {
            if (scores[i] % 2 == 0) {
                evenCount++;
            } else {
                oddCount++;
            }
        }
        System.out.println("奇数个数: " + oddCount);
        System.out.println("偶数个数: " + evenCount);

        float a = 2.0f;
    }

    public static void main(String[] args) {

    }

//    16、题目：一个5位数，判断它是不是回文数。即12321是回文数，个位与万位相同，十位与千位相同。
//    char[] array = {'a' , 'b', 'c', 'b' , 'a'};
    @Test
    public void test66() {
        // "abcba"
        //String str = "abcba";
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入字符串：");
        String str = scanner.next();
        char[] array = str.toCharArray();
        boolean isHuiWen = true;
        for (int i = 0; i < array.length / 2; i++) {
            if (array[i] != array[array.length-i-1]) {
                isHuiWen = false;
                break;
            }
        }

        if (isHuiWen) {
            System.out.println("是回文");
        } else {
            System.out.println("不是回文");
        }
    }

    //17、输入一行字符串，分别统计出其中英文字母、空格、数字和其它字符的个数。
    @Test
    public void test88() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入字符串：");
        String str = scanner.nextLine();// "7**^DDjsg6fh gDG D^("
        char[] array = str.toCharArray();
        int countLetter = 0;
        int countNum = 0;
        int countSpace = 0;
        int countOther = 0;
        for (int i = 0; i < array.length; i++) {
            char ch = array[i];
            if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) {
                countLetter++;
            } else if (ch >= '0' && ch <= '9') {
                countNum++;
            } else if (ch == ' ') {
                countSpace++;
            } else {
                countOther++;
            }
        }
        System.out.println("字母出现的次数：" + countLetter);
        System.out.println("数字出现的次数：" + countNum);
        System.out.println("空格出现的次数：" + countSpace);
        System.out.println("其他出现的次数：" + countOther);
    }

}
